package org.spolo.android.support.tween;

import org.spolo.android.support.nodetree.Vcanvas;

/**
 * 是一个从0开始到目标数值的差值器,所计算出来的值都是相差很小平均量例如:2.90,3.00,3.01..,也就是平均量
 * 
 * @date 2012-5-22
 */
public class FloatInterpolate extends InterpolateBase {
	private float howlong;
	private float dx;
	private float lastdx = 0;

	/**
	 * @param v
	 * @param y
	 * @param time
	 */
	public FloatInterpolate(Vcanvas v, float y, long time, int type) {
		super(v, type);
		this.dx = y;
		this.howlong = time;
	}

	@Override
	public void stepIt(long tick) {
		float factor = ((tick - startTick) / this.howlong);
		if (factor >= 1.0) {
			Target.setValues(this.changeType, (dx - lastdx), 0);
			// this.Target.Rotate((1 - lastFactor) * taget_Value);
			this.isFinish = true;
			return;
		}
		float mx = factor * dx - lastdx;
		lastdx = factor * dx;
		Target.setValues(this.changeType, mx, 0);
		// this.Target.Rotate(mx);
		this.isFinish = factor > 1.0;
	}
}
